<?php

require dirname(__FILE__).'/../../../bootstrap/Doctrine.php';

$t = new lime_test(24);
$table = Doctrine_Core::getTable('BlogPost');

$t->diag('->hasSubscriber()');
$p1 = $table->findOneBySlug('my-first-blog-post');
$p2 = $table->findOneBySlug('unpublished-post');
$t->ok($p1->hasSubscriber('user@example.com'), '->hasSubscriber() returns true');
$t->is($p2->hasSubscriber('user@example.com'), false, '->hasSubscriber() returns false');

$t->diag('->subscribe()');
$t->is($p1->hasSubscriber('foo@example.com'), false, '->subscribe() does not have the email');
$p1->subscribe('foo@example.com');
$t->ok($p1->hasSubscriber('foo@example.com'), '->subscribe() registered the email');
$p1->subscribe('toto@example.com', 'fr');
$t->ok($p1->hasSubscriber('toto@example.com'), '->subscribe() registered a new email');
$t->is(count($p1->getSubscribers()), 4, '->subscribe() the post has 4 subscribers');

$t->diag('->getSubscribersExcept()');
$t->isa_ok($p1->getSubscribersExcept('user@example.com'), 'array', '->getSubscribersExcept() returns an array');
$t->is(count($p1->getSubscribersExcept('user@example.com')), 3, '->getSubscribersExcept() returns 3');
$t->is(count($p1->getSubscribersExcept('noone@example.com')), 4, '->getSubscribersExcept() returns 4');

$t->diag('->isCommentable()');
$t->ok($p1->isCommentable(), '->isCommentable() returns true');
$t->is($p2->isCommentable(), false, '->isCommentable() returns false');

$t->diag('->isModerated()');
$t->ok($p1->isModerated(), '->isModerated() returns true');
$t->is($p2->isModerated(), false, '->isModerated() returns false');

$t->diag('->getYear()');
$t->is($p1->getYear(), '2010', '->getYear() returns 2010');

$t->diag('->getMonth()');
$t->is($p1->getMonth(), '01', '->getMonth() returns 01');

$t->diag('->getDay()');
$t->is($p1->getDay(), '01', '->getDay() returns 01');

$t->diag('->getCommentsCount()');
$t->is($p1->getCommentsCount(), 4, '->getCommentsCount() returns 4');
$t->is($p2->getCommentsCount(), 0, '->getCommentsCount() returns 0');

$t->diag('->getPublishedComments()');
$t->is(count($p1->getPublishedComments()), 3, '->getPublishedComments() returns 3');
$t->is(count($p2->getPublishedComments()), 0, '->getPublishedComments() returns 0');

$t->diag('->incrementHits()');
$p1->incrementHits();
$t->is($p1->getMaxHits(), 1, '->getMaxHits() returns 1');
$p1->incrementHits();
$t->is($p1->getMaxHits(), 2, '->getMaxHits() returns 2');

$t->diag('->setSourceExcerpt()');
$content = <<<EOT
Fusce at rutrum sapien. Ut luctus **ipsum ut enim pharetra quis commodo dui**
convallis. Curabitur rutrum, leo non tristique viverra, lectus massa pulvinar
quam, quis rutrum arcu urna sollicitudin diam. Mauris pharetra quam vitae nibh
venenatis vestibulum pharetra dui luctus. Proin blandit adipiscing velit, at
sodales nibh fermentum vitae. Aenean urna velit, dictum et rhoncus ultrices,
pretium in nisi. Nunc dui tellus, bibendum quis luctus sed, sagittis et quam.
Integer eleifend turpis eget mauris gravida vitae gravida libero euismod. Aenean
viverra metus vitae orci accumsan posuere. Praesent ac elit id lacus adipiscing
egestas iaculis in tortor. Praesent vehicula ligula sed felis fringilla tempus.
Sed in ipsum tellus. Sed id accumsan nibh.

    [css]
    h1 {
      font-size: 15px;
    }
          
    h2 {
      font-size: 13px;
    }

Praesent et dolor neque, a pulvinar tellus. Nulla aliquet, nulla vel tincidunt
volutpat, nisi justo euismod dolor, vel tempus diam orci vitae nunc. Donec erat
tellus, malesuada eget bibendum sed, semper id tellus. Duis vehicula, quam vel
molestie viverra, augue lectus lobortis diam, sed consectetur purus augue in
velit. Aliquam sit amet sem eget sapien porta aliquam. Quisque malesuada, tortor
sed euismod porta, ipsum felis condimentum dolor, ut vulputate massa ante ac
est. Duis at urna et velit placerat vestibulum. Vestibulum ante ipsum primis in
faucibus orci luctus et ultrices posuere cubilia Curae; Morbi et ipsum tortor,
quis cursus mauris. Donec ultrices risus in tellus consectetur eu eleifend urna
blandit. Suspendisse vel magna libero. Morbi eu enim urna. Aliquam augue diam,
malesuada eu dignissim nec, euismod non elit.
EOT;

$p1->setSourceExcerpt($content);

$t->like($p1->getCachedExcerpt(), '/<pre class="css"/', '->setSourceExcerpt() converts markdown to html');

$t->diag('->setSourceContent()');
$p1->setSourceContent($content);
$t->like($p1->getCachedContent(), '/<pre class="css"/', '->setSourceContent() converts markdown to html');

//$t->like($p1->getSourceExcerpt())